# 封装ihrm  登录模块
import requests


class IhrmApi:
    # 登录
    @classmethod
    def ihrm_login(cls, login_body):
        # 请求url
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_re = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_re

    # 添加员工
    @classmethod
    def ihrm_add_emp(cls, token, add_emp_body):
        add_emp_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_emp_header = {"Content-Type": "application/json", "Authorization": token}
        add_emp_resp = requests.post(url=add_emp_url, headers=add_emp_header, json=add_emp_body)
        return add_emp_resp

    # 查询员工
    @classmethod
    def ihrm_query_emp(cls, emp_id, token):
        query_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        query_emp_header = {"Authorization": token}
        query_emp_resp = requests.get(url=query_emp_url, headers=query_emp_header)
        return query_emp_resp

    # 修改员工
    @classmethod
    def ihrm_modify_emp(cls, emp_id, token, modify_emp_body):
        modify_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        modify_emp_header = {"Content-Type": "application/json", "Authorization": token}
        modify_emp_resp = requests.put(url=modify_emp_url, headers=modify_emp_header, json=modify_emp_body)
        return modify_emp_resp

    # 删除员工
    @classmethod
    def ihrm_delete_emp(cls, emp_id, token):
        delete_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        delete_emp_header = {"Authorization": token}
        delete_emp_resp = requests.delete(url=delete_emp_url, headers=delete_emp_header)
        return delete_emp_resp

    # 添加部门
    @classmethod
    def ihrm_add_dept(cls, token, add_dept_body):
        add_dept_url = "http://ihrm2-test.itheima.net/api/company/department"
        add_dept_header = {"Content-Type": "application/json", "Authorization": token}
        add_dept_resp = requests.post(url=add_dept_url, headers=add_dept_header, json=add_dept_body)
        return add_dept_resp

    # 查询部门
    @classmethod
    def ihrm_query_dept(cls, dept_id, token):
        query_dept_url = "http://ihrm2-test.itheima.net/api/company/department/" + dept_id
        query_dept_header = {"Authorization": token}
        query_dept_resp = requests.get(url=query_dept_url, headers=query_dept_header)
        return query_dept_resp

    # 修改部门
    @classmethod
    def ihrm_modify_dept(cls, token, dept_id, modify_dept_body):
        modify_dept_url = "http://ihrm2-test.itheima.net/api/company/department/" + dept_id
        modify_dept_header = {"Content-Type": "application/json", "Authorization": token}
        modify_dept_resp = requests.put(url=modify_dept_url, headers=modify_dept_header, json=modify_dept_body)
        return modify_dept_resp

    # 删除部门
    @classmethod
    def ihrm_delete_dept(cls, token, dept_id):
        delete_dept_url = "http://ihrm2-test.itheima.net/api/company/department/" + dept_id
        delete_dept_header = {"Authorization": token}
        delete_dept_resp = requests.delete(url=delete_dept_url, headers=delete_dept_header)
        return delete_dept_resp

# if __name__ == '__main__':
#     token = "bf72a6c6-3c20-4e5f-a839-c93ac92f4adb"
#     dept_id = "1574006659762745344"
#     rest = IhrmApi.ihrm_query_dept(token, dept_id)
#     print(rest.json())
